package com.songcha.sakura.ui.view

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.View
import com.songcha.library_common.util.dp2px


@SuppressLint("AppCompatCustomView")
class ShelfBottomView : View {

    private val buttomHeight=12f.dp2px()
    private val topHeight=20f.dp2px()
    private val leftOffset=20f.dp2px()
    private val rightOffset=15f.dp2px()
    private lateinit var mBottomPaint:Paint
    private lateinit var mLinePaint:Paint

    constructor(context: Context) : super(context) {
        initView(context,null)
    }

    constructor(context: Context, attrs: AttributeSet):this(context,attrs,0){

    }

    constructor(context: Context, attrs: AttributeSet, defStyle:Int):this(context,attrs,defStyle,0){

    }

    constructor(context: Context, attrs: AttributeSet, defStyle:Int, defRes:Int):super(context,attrs,defStyle,defRes){
        initView(context,attrs)
    }

    private fun initView(context: Context, attrs: AttributeSet?){
        mBottomPaint= Paint()
        mBottomPaint.style=Paint.Style.FILL
        mBottomPaint.color=Color.parseColor("#7fa85727")
        mBottomPaint.strokeWidth=1f

        mLinePaint= Paint()
        mLinePaint.style=Paint.Style.FILL
        mLinePaint.color=Color.parseColor("#a85727")
        mLinePaint.strokeWidth=1f

    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        //setMeasuredDimension()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)

        if(canvas!=null){

            val path= Path()
            path.moveTo(0f,height.toFloat())
            path.lineTo(0f,height.toFloat()-buttomHeight)
            path.lineTo(width.toFloat(),height.toFloat()-buttomHeight)
            path.lineTo(width.toFloat(),height.toFloat())

            path.moveTo(0f,height.toFloat()-buttomHeight)
            path.lineTo(leftOffset,height.toFloat()-buttomHeight-topHeight)
            path.lineTo(width.toFloat()-rightOffset,height.toFloat()-buttomHeight-topHeight)
            path.lineTo(width.toFloat(),height.toFloat()-buttomHeight)

            canvas.drawPath(path,mBottomPaint)

            canvas.drawLine(0f,height.toFloat()-buttomHeight,width.toFloat(),height.toFloat()-buttomHeight,mLinePaint)

        }

    }


}